package club.emergency.wechat.wechat_api.consumer.service.fallback_factory;

import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.response.StatusCode;
import club.emergency.wechat.model.wechat_api.UserInfo;
import club.emergency.wechat.model.wechat_api.UserInfoSimple;
import club.emergency.wechat.wechat_api.consumer.service.WechatApiConsumer;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.wechat_api.consumer.service.fallback_factory
 * Date: 2019/3/25
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@Component
public class WechatApiFallbackFactory implements FallbackFactory<WechatApiConsumer> {
    @Override
    public WechatApiConsumer create(Throwable throwable) {
        return new WechatApiConsumer() {
            @Override
            public String getOpenIdByCode(String code) {
                return ResponseEntity.error(StatusCode.REQUEST_WECHAT_ERROR, "根据code获取openId失败！", throwable.getMessage());
            }

            @Override
            public String uploadImageReturnUrl(String fileName, byte[] bytes) {
                return ResponseEntity.error(StatusCode.REQUEST_WECHAT_ERROR, "上传图文消息内的图片获取URL失败！", throwable.getMessage());
            }

            @Override
            public String getUserOpenIdList() {
                return ResponseEntity.error(StatusCode.REQUEST_WECHAT_ERROR, "获取关注的用户信息列表失败！", throwable.getMessage());
            }

            @Override
            public String getUserInfoByOpenId(String openId) {
                return ResponseEntity.error(StatusCode.REQUEST_WECHAT_ERROR, "根据OpenId获取人员详细信息失败！", throwable.getMessage());
            }

            @Override
            public List<UserInfo> getUserInfoList(UserInfoSimple userInfoSimple) {
                return null;
            }
        };
    }
}
